<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="muni.ilo.dto.ContribuyenteDTO"%>
<%@page import="java.text.DateFormat"%>
<%@page import="org.apache.tomcat.jni.Local"%>
<%@page import="java.util.Locale"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="cs/mc.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function CambiarFormulario(){
	switch(document.forms[0].tipo.selectedIndex){
		case 0: 
			document.forms[0].valor.value = document.forms[0].razsoc.value;
			document.forms[0].razsoc.disabled=true;
			document.forms[0].razsoc.value = '';
			document.forms[0].boton01.disabled=true;
			break;
		case 1: 
			document.forms[0].razsoc.disabled=false;
			if(document.forms[0].valor.value != ''){
				document.forms[0].razsoc.value = document.forms[0].valor.value;
				document.forms[0].boton01.disabled=true;
			}
			break;

	}
}
function validarCampos(campo) {
	if(campo.id == 'email'){
		 var re = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/;
				if(campo.value == ''){
					return;
				}
		    	if(!re.exec(campo.value))    {
			    	alert("La dirección de email es incorrecta.");
					  campo.style.color='red';
					  campo.focus();
					  campo.select();
			    }else{
			    	document.getElementById("email").style.color='blue';
			    }
					
	} if(campo.id == 'tel'){
		if(isNaN(campo.value)||campo.value.length < '7'){
			alert("Debe introducir un valor numerico de\n7 o 9 cifras");
			campo.style.color='red';
			campo.focus();
			campo.select();
		}else{
			document.getElementById("tel").style.color='blue';
		}	
	}
}
function activaBoton(field) {
	var retorno = 0;
	var elementos = document.forms[0].elements.length;
	var obj = document.getElementById("boton01");
	if(document.forms[0].tipo.selectedIndex == 0){ 
		for(i=0; i < elementos; i++){
		if(document.forms[0].elements[i].type == 'text' && document.forms[0].elements[i].name != 'razsoc' ){
			if(document.forms[0].elements[i].value != '' ){
				document.forms[0].elements[i].style.backgroundColor = '#91E148';
				retorno ++ ;
			}else{
				document.forms[0].elements[i].style.backgroundColor = '#ff0000';
				document.forms[0].elements[i].style.color = '#ffffff';
				}
			}
		}
	}else if(document.forms[0].tipo.selectedIndex == 1){ 
		for(i=0; i < elementos; i++){
		if(document.forms[0].elements[i].type == 'text' ){
			if(document.forms[0].elements[i].value != ''){
				document.forms[0].elements[i].style.backgroundColor = '#91E148';
				retorno ++;
			}else{
				document.forms[0].elements[i].style.backgroundColor = '#ff0000';
				document.forms[0].elements[i].style.color = '#ffffff';
				}
			}
		}
	}
	var nom = field.name;
	var val = field.value; 
	if (retorno == 5 || retorno == 6 ){
		if(document.forms[0].tipo.selectedIndex == 0){
			if(nom == 'razsoc'){
				obj.disabled = false;
				return;
			}
		}else{
			if(nom == 'razsoc'){
				if(val != '')
					obj.disabled = false;
				else
					obj.disabled = true;
				return;
			}
		}
		if(nom != 'razsoc'|| nom != 'email'){
			if(val!= ''){
				obj.disabled = false;
			}else{
				obj.disabled = true;
			}
			return;
		}
		obj.disabled = false;	
	}
	if (retorno < 5 ){
		if(nom != 'razsoc'|| nom != 'email'){
			obj.disabled = true;
		}
	}
}

</script>
</head>

<%
// recuperamos el objeto cliente que llega en el request
ContribuyenteDTO contribuyente = (ContribuyenteDTO)request.getAttribute("b_contribuyente");
%>


<body onload="CambiarFormulario();">

	
	<table>
		
		<tr>

			<!--  aqui va el cuerpo -->
			<td class="control" >
			
				<form action="contribuyente.do"  method="post" >
				  		<input type="hidden" name="valor" value="">	
				  	<input type="hidden" name="operacion" value="modificar" />
				 		
				<table>
					<tr class="titulo" >
						<td colspan="2" align="center" > <font color="#000CCC"><strong>Modificar  Contribuyentes </strong></font></td>
					</tr>
					<tr class="control" >
						<td>Codigo: </td>
						<td><font color="#0000CC"><strong><%= contribuyente.getCodigo() %></strong></font>  
						<input type="hidden" name="cod" value="<%= contribuyente.getCodigo() %>"> </td>
					</tr>
					<tr class="control"  >
						<td>Tipo: </td>
						<td> 
												
						<%if(contribuyente.getTipo().equals("PERSONA NATURAL")){ %>
						<select name="tipo" id="tipo" onchange="CambiarFormulario();">
							<option value="PERSONA NATURAL"  selected="selected"> Persona Natural </option>
							<option value="PERSONA JURIDICA" > Persona Juridica </option>
						</select> 
						<%}else{ %>
						<select name="tipo" id="tipo" onchange="CambiarFormulario();">
							<option value="PERSONA NATURAL"  > Persona Natural </option>
							<option value="PERSONA JURIDICA" selected="selected"> Persona Juridica </option>
						</select> 
						<%} %>
						 
						</td>
					</tr>
					<tr class="control" >
						<td>Raz&oacute;n social: </td>
						<%if(contribuyente.getRazsoc()!= null){ %>
						<td> <input type="text" name="razsoc" size="25" id="razsoc" value="<%= contribuyente.getRazsoc() %>" onblur="activaBoton(this);"> </td>
						<%}else{ %>
						<td> <input type="text" name="razsoc" size="25" id="razsoc" onblur="activaBoton(this);"> </td>
						<%} %>
					</tr>
					<tr class="control" >
						<td>Nombre: </td>
						<td> <input type="text" name="nombre" size="25" value="<%= contribuyente.getNombre() %>" onblur="activaBoton(this);"> </td>
					</tr>
					<tr class="control" >
						<td>Apellido  Paterno: </td>
						<td> <input type="text" name="apePat" size="10" value="<%= contribuyente.getApePat() %>" onblur="activaBoton(this);"> </td>
					</tr>
					<tr class="control" >
						<td>Apellido  Materno: </td>
						<td> <input type="text" name="apeMat" size="10" value="<%= contribuyente.getApeMat() %>" onblur="activaBoton(this);" > </td>
					</tr>
					<tr class="control" >
						<td>Lugar de Residencia: </td>
						<td><label><strong><%= contribuyente.getLugRes() %></strong> </label>
						 <input  type="hidden" name="resi"  value="<%= contribuyente.getLugRes() %>"> </td>
					</tr>
					<tr class="control"  >
						<td>Sexo: </td>
						<td> 
												
						<%if(contribuyente.getSexo().equals("M")){ %>
						<select name="sexo" >
							<option value="M"  selected="selected"> Masculino </option>
							<option value="F" > Femenino </option>
						</select> 
						<%}else{ %>
						<select name="sexo" >
							<option value="M"  > Masculino </option>
							<option value="F" selected="selected"> Femenino </option>
						</select> 
						<%} %>
						 
						</td>
					</tr>
					<tr class="control" >
						<td>Telefono: </td>
						<td> <input type="text" id="tel" name="tel" size="10" maxlength="9" value="<%= contribuyente.getTelefono() %>" onblur="validarCampos(this);activaBoton(this);"> </td>
					</tr>
					<tr class="control" >
						<td>E-mail: </td>
						<td> <input type="text" id="email" name="email" size="10" value="<%= contribuyente.getEmail() %>" onblur="validarCampos(this);activaBoton(this);"> </td>
					</tr>
					<tr class="control"  >
						<td>Fecha de Registro: </td>
						<%
						Locale loc = new Locale("es","PE");
						DateFormat dateF = DateFormat.getDateInstance(DateFormat.SHORT,loc); %>
						<td><font  color="#000000"><strong><%= dateF.format(contribuyente.getFecReg()) %></strong></font>
						<input type="hidden" name="fecreg" value="<%= dateF.format(contribuyente.getFecReg()) %>"></td>
					</tr>
					<tr class="control"  >
						<td>Fecha de Actualizacion: </td>
						<%
						Locale loc2 = new Locale("es","PE");
						DateFormat dateF2 = DateFormat.getDateInstance(DateFormat.SHORT,loc2); %>
						<td><font color="#FFFFFF"><strong></strong><%= dateF2.format(contribuyente.getFecAct()) %> </font> </td>
					</tr>
					<tr class="control" >
						<td colspan="2" align="right"  > 
							<input 
								type="submit" 
								name="boton01"
								id="boton01" 
								value="Modificar" > 
						</td>
						<td colspan="2" align="right"  > 
							<a href="contribuyente.do?operacion=listar"><img src="images/btndtsal.JPG"/></a>
						</td>
					</tr>
				</table>
				
				</form>

			</td>
			
			
		</tr>
		
	</table>
	
</body>
</html>